package cn.bytecollege.admin.service;

import cn.bytecollege.admin.dao.MerchantDao;
import cn.bytecollege.common.entity.Merchant;
import cn.bytecollege.common.entity.Page;

import java.util.List;

public class MerchantService {
    private MerchantDao merchantDao = null;
    public MerchantService() {merchantDao = new MerchantDao();}

    /**
     * 分页查询商家信息
     * @param pageIndex
     * @param pageSize
     * @return
     */
    public Page<Merchant> findMerchantByPage(int pageIndex, int pageSize){
        List<Merchant> list = merchantDao.findMerchantByPage(pageIndex,pageSize);
        //查询商家总数
        int count = merchantDao.count();
        //封装page
        Page<Merchant> page = new Page<>();
        //当前页码
        page.setCurrentIndex(pageIndex);
        page.setPageSize(pageSize);
        //计算总页数
        page.setTotalPage(count);
        //封装总条数
        page.setTotal(count);
        page.setList(list);
        //封装当前页面
        page.setPageIndex();
        return page;
    }

}
